package co.wizardattack.model;

import java.io.IOException;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.opengl.texture.TextureManager;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import android.content.Context;

public class Wizard {
	/**
	 * Constantes
	 */	
	private final String CONS_IMAGE_PATH = "images/";
	private final String CONS_IMAGE_WIZARD = "wizardSecuencia.png";	
	private final int CONS_ATLAS_WIDTH = 724;
	private final int CONS_ATLAS_HEIGTH = 1096;
	private final int CONS_IMAGE_COLUMNS = 4;
	private final int CONS_IMAGE_ROWS = 4;

	/**
	 * Atributos
	 */
	private float posX = 300;
	private float posY = 255;
	private BitmapTextureAtlas atlasAnimatedWizard;
	private ITiledTextureRegion textureAnimatedWizard;
	private AnimatedSprite spriteAnimatedWizard;
	/**
	 * Constructor
	 */
	public Wizard() {
				
	}
	/**
	 * Metodos
	 */
	public void onCreateResourcesWizard(TextureManager textureManager, Context context) throws IOException {
		BitmapTextureAtlasTextureRegionFactory.setAssetBasePath(CONS_IMAGE_PATH);
		atlasAnimatedWizard = new BitmapTextureAtlas(textureManager, CONS_ATLAS_WIDTH, CONS_ATLAS_HEIGTH ,TextureOptions.DEFAULT);
		textureAnimatedWizard = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(atlasAnimatedWizard, context, CONS_IMAGE_WIZARD, 0, 0, CONS_IMAGE_COLUMNS, CONS_IMAGE_ROWS);		
		atlasAnimatedWizard.load();		
	}
	
	public void onCreateSceneWizard(VertexBufferObjectManager vertexBufferObjectManager){
		this.spriteAnimatedWizard = new AnimatedSprite(posX, posY, textureAnimatedWizard,  vertexBufferObjectManager);		
	}
		
	//ANIMACION
//	public void animatedBack() {	
//		long[] duracionFrame = { 200, 200, 200, 200 , 200 , 200 , 200 , 200 };
//		spriteAnimatedWizard.animate(duracionFrame, 0, 7, true);
//	}
	 void animatedRight() {	
		 long[] duracionFrame = { 100, 100, 100, 100 , 100 , 100 , 100 , 100 };
			spriteAnimatedWizard.animate(duracionFrame, 0, 7, true);
	}
//	public void animatedFront() {	
//		long[] duracionFrame = { 200, 200, 200, 200 };
//		spriteAnimatedWizard.animate(duracionFrame, 7, 9, true);
//	}
	public void animatedLeft() {	
		long[] duracionFrame = { 100, 100, 100, 100 , 100 , 100 , 100 , 100 };
		spriteAnimatedWizard.animate(duracionFrame, 8, 15, true);
	}

	//GETS AND SETS
	public float getPosX() {
		return spriteAnimatedWizard.getX();
	}
	public void setPosX(float posX) {
		spriteAnimatedWizard.setX(posX);
		this.posX = posX;
	}
	public float getPosY() {
		return spriteAnimatedWizard.getY();
	}
	public void setPosY(float posY) {
		spriteAnimatedWizard.setY(posY);
		this.posY = posY;
	}
	public AnimatedSprite getSpriteAnimatedWizard() {
		return spriteAnimatedWizard;
	}
	
}
